<template>
  <view class="container">
    <view class="question-header">
      <view class="question-title">{{ question.title }}</view>
      <view class="question-meta">
        <difficulty-tag :difficulty="question.difficulty" />
      </view>
    </view>
    <view class="question-content">
      <view class="content-section">
        <view class="section-title">参考答案</view>
        <view class="section-content answer">
          <ua-markdown :source="question.answer" :show-line="false"/>
        </view>
      </view>
    </view>

    <view class="action-bar" v-if="showActionBar">
      <view class="nav-icons" :style="showNextAndPreButton?'':'visibility:hidden'">
        <view 
          class="nav-icon prev-icon" 
          :class="{ disabled: !hasPrev }" 
          @click="goToPrevQuestion"
        >
          <u-icon name="arrow-left" size="24" color="#00cc86"></u-icon>
        </view>
        <view 
          class="nav-icon next-icon" 
          :class="{ disabled: !hasNext }" 
          @click="goToNextQuestion"
        >
          <u-icon name="arrow-right" size="24" color="#00cc86"></u-icon>
        </view>
      </view>
      
      <view class="center-icons">
        <view 
          class="ai-icon"
          @click="goToAskAI"
        >
          <image :src="'https://youke1.picui.cn/s1/2025/09/18/68cbfef2a3582.png'" mode="" class="ai-image"></image>
        </view>
      </view>
      
      <view class="action-icons">
        <view 
          class="action-icon collect-icon" 
          @click="toggleCollect"
        >
          <u-icon :name="isCollected ? 'star-fill' : 'star'" size="24" color="#00cc86"></u-icon>
        </view>
        <view 
          class="action-icon share-icon" 
          @click="toggleMastered"
        >
          <u-icon :name="isMastered ? 'checkmark-circle-fill' : 'checkmark-circle'" size="24" color="#00cc86"></u-icon>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import DifficultyTag from '@/components/difficulty-tag.vue';
import UaMarkdown from '@/components/ua2-markdown/ua-markdown.vue';

export default {
  components: {
    DifficultyTag,
    UaMarkdown
  },
  props: {
    // 题目数据
    question: {
      type: Object,
      default: () => ({
        id: 1,
        title: '',
        categoryName: '',
        difficulty: '★★★',
        views: 0,
        description: '',
        answer: '',
        tags: []
      })
    },
    // 当前题目索引
    currentQuestionIndex: {
      type: Number,
      default: 0
    },
    // 题目列表
    questionList: {
      type: Array,
      default: () => []
    },
    // 是否已收藏
    isCollected: {
      type: Boolean,
      default: false
    },
    // 是否已掌握
    isMastered: {
      type: Boolean,
      default: false
    },
    // 是否显示操作栏
    showActionBar: {
      type: Boolean,
      default: true
    },
    // 是否显示操作栏
    showNextAndPreButton: {
      type: Boolean,
      default: true
    }


  },
  computed: {
    hasPrev() {
      return this.currentQuestionIndex > 0;
    },
    hasNext() {
      return this.currentQuestionIndex < this.questionList.length - 1;
    }
  },
  methods: {
    goToPrevQuestion() {
      if (this.hasPrev) {
        this.$emit('goToPrevQuestion');
      }
    },
    
    goToNextQuestion() {
      if (this.hasNext) {
        this.$emit('goToNextQuestion');
      }
    },
    
    toggleCollect() {
      this.$emit('toggleCollect');
    },
    
    toggleMastered() {
      this.$emit('toggleMastered');
    },
    
    goToAskAI() {
      this.$emit('goToAskAI');
    }
  }
};
</script>

<style scoped>
.container {
  min-height: 100vh;
  padding: 180rpx 15px 15px;
  padding-bottom: 120px;
  background: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiBmaWxsPSJub25lIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMjY3IiBoZWlnaHQ9IjkxOSIgdmlld0JveD0iMCAwIDEyNjcgOTE5Ij48ZGVmcz48bGluZWFyR3JhZGllbnQgeDE9IjAuODUxMjA2NDgxNDU2NzU2NiIgeTE9IjAuOTI1NjAzMTUxMzIxNDExMSIgeDI9IjAuMzA2NjA3NDUxMjE3NTkwMzciIHkyPSIwLjc1NjY1OTIyODgyNTk1NjUiIGlkPSJtYXN0ZXJfc3ZnMF85XzAzNyI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI0Y0RjVGQSIgc3RvcC1vcGFjaXR5PSIxIi8+PHN0b3Agb2Zmc2V0PSIxMDAlIiBzdG9wLWNvbG9yPSIjRjRG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zz4=");
  background-position-y: -260rpx;
  background-size: contain;
  background-repeat: no-repeat;
  background-color: #ffffff;
}

.question-header {
  padding: 10px;
  margin-bottom: 15px;
  background: transparent;
}

.question-title {
  font-size: 22px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  font-size: 14px;
  color: #999;
}

.meta-item {
  background-color: #f0f0f0;
  padding: 5px 10px;
  border-radius: 5px;
  margin-right: 10px;
  margin-bottom: 5px;
}

.question-content {
  background: transparent;
  border-radius: 10px;
  padding: 10px;
}

.content-section {
  margin-bottom: 25px;
}

.content-section:last-child {
  margin-bottom: 0;
}

.section-title {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.section-content {
  font-size: 15px;
  color: #666;
  line-height: 1.6;
}

.section-content.answer {
  padding: 0px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
}

.tag {
  background-color: #e0f0ff;
  color: #007AFF;
  padding: 5px 10px;
  border-radius: 5px;
  margin-right: 10px;
  margin-bottom: 10px;
  font-size: 14px;
}


.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  position: fixed;
  bottom: 0px;
  left: 0;
  right: 0;
  background-color: #fffffffa;
  padding: 10px 15px 30px;
}

.nav-icons {
  display: flex;
  align-items: center;
}

.nav-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 5px;
}

.nav-icon.disabled {
  opacity: 0.5;
}

.center-icons {
  display: flex;
  align-items: center;
  width: 50%;
  justify-content: center;
}

.ai-icon {
  width: fit-content;
  height: 40px;
  padding: 0px 20px;
  border-radius: 20px;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -1px 9px 19px 9px #8484840d
}

.ai-icon .ai-image {
  height: 18px;
  width: 55px;
}

.action-icons {
  display: flex;
}

.action-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 5px;
}
</style>